package com;

import java.util.Scanner;

public class GuessNumberGame {

    public static void main(String[] args) {
        int x = (int) (Math.random() * 100);
        boolean start = true;
        int guess = 7, inNumber, big = 100,small = 1;
        System.out.println("100以内数已生成");
        Scanner in = new Scanner(System.in);
        while (start) {
            if (guess<=0){
                System.out.println("游戏结束");
                System.out.println("是否继续游戏? Y/N");
                String str = in.next();
                switch (str){
                    case "Y":System.out.println("游戏继续");big=100;small=1;guess=7;x=(int)(Math.random()*100);break;
                    case "N":System.out.println("游戏结束");start=false;break;
                }
            }
            System.out.println("请输入一个" + small + "~" + big + "数(还可尝试"+guess+"次):");
            inNumber = in.nextInt();
            if (inNumber == x) {
                System.out.println("猜对啦!这个数是：" + x);
                System.out.println("是否继续游戏? Y/N");
                String str = in.next();
                switch (str){
                    case "Y":System.out.println("游戏继续");big=100;small=1;guess=0;x=(int)(Math.random()*100);break;
                    case "N":System.out.println("游戏结束");start=false;break;
                }

            } else if (inNumber > x) {
                System.out.println("猜大啦");
                big = inNumber;
                guess--;
            } else if (inNumber < x) {
                System.out.println("猜小啦");
                small = inNumber;
                guess--;
            }
        }
    }
}
